<script setup>
import { useRouter } from "vue-router";
import del from "@iconify-icons/ri/delete-bin-line";
import More2Fill from "@iconify-icons/ri/more-fill";
import copy from "@iconify-icons/ep/copy-document";
import edit from "@iconify-icons/ri/edit-line";
import move from "@iconify-icons/ri/file-transfer-line";
defineOptions({
  name: "fileCard"
});

const props = defineProps({
  fileList: []
});

const router = useRouter();
const emit = defineEmits([
  "handleClickOption",
  "handleDelFile",
  "handleEditFile"
]);

const handleClickOption = file => {
  emit("handleClickOption", file);
};
const handleDelFile = file => {
  emit("handleDelFile", file);
};
const handleEditFile = (file, type) => {
  file.type = type;
  emit("handleEditFile", file);
};
const handleGoTagGraph = file => {
  router.push({ name: "tagGraph", query: { ...file } });
};
</script>

<template>
  <el-row :gutter="16">
    <el-col
      v-for="(file, index) in fileList"
      :key="index"
      :xs="24"
      :sm="12"
      :md="8"
      :lg="6"
      :xl="4"
    >
      <div class="list-card-item bg-bg_color">
        <div class="list-card-item_detail--img" @click="handleGoTagGraph(file)">
          <img
            style="height: auto; max-height: 100%"
            :src="file.canvasPicUrl"
            :alt="file.name"
          />
        </div>
        <div class="list-card-item_detail--name flex justify-between">
          <span> {{ file.name }}</span>
          <span>{{ file.width }}*{{ file.height }}</span>
        </div>
        <div class="prop">
          <el-dropdown trigger="click">
            <span class="iconsbox">
              <IconifyIconOffline :icon="More2Fill" class="icons" />
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="handleEditFile(file, 'dir')">
                  <iconify-icon-offline :icon="edit" class="ml-1 mr-1" />
                  重命名
                </el-dropdown-item>
                <el-dropdown-item @click="handleClickOption(file)">
                  <iconify-icon-offline :icon="copy" class="ml-1 mr-1" />
                  复制或移动
                </el-dropdown-item>
                <el-dropdown-item @click="handleDelFile(file)">
                  <template #default>
                    <iconify-icon-offline :icon="del" class="ml-1 mr-1" />
                    删除
                  </template>
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<style scoped lang="scss">
.btn {
  padding: 5px 0;
  margin: 5px 0;
  font-size: 15px;
  border-right: 2px solid #e5e7ec;
}

.btn:last-child {
  border-right: 0 solid #e5e7ec;
}

.list-card-item {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 10px 0;
  overflow: hidden;
  cursor: pointer;
  border-radius: 5px;

  &_detail {
    flex: 1;
    min-height: 140px;
    padding: 15px 20px;

    &--name {
      padding: 0 10px;
      margin: 24px 0 8px;
      margin-top: 0;
      font-size: 14px;
      font-weight: 400;
    }

    &--img {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 200px;
      padding: 10px;
      margin-bottom: 10px;
      background-color: rgb(225 225 225);
    }
  }

  .prop {
    position: absolute;
    top: 8px;
    right: 0;
    z-index: 100;

    .icons {
      font-size: 0;
    }
  }
}

.list-card-item:hover {
  z-index: 2;
  border: 1px solid #067bef !important;
  opacity: 1;
  transform: translateY(-2px);

  .iconsbox {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 18px;
    margin-right: 8px;
    font-size: 18px;
    font-weight: 400;
    line-height: 18px;
    color: #fff;
    text-align: center;
    cursor: pointer;
    background-color: #c6c6c6;
    border-radius: 4px;

    .icons {
      font-size: 22px;
    }
  }
}
</style>
